const  multer = require('multer');

let storage = multer.diskStorage({
    //设置上传后文件路径，uploads文件夹会自动创建。
    destination: function (req, file, cb) {
        let path = `uploads/${req.session.user.name}/${req.query.className}`;
        cb(null, path);
    },
    //给上传文件重命名，获取添加后缀名
    filename: function (req, file, cb) {
        let fileFormat = (file.originalname).split(".");
        cb(null, Date.now() + "." + fileFormat[fileFormat.length - 1]);
    }
});
 //添加配置文件到muler对象。
let upload = multer({
      storage: storage
});

 //导出对象
module.exports = upload;
